package com.dlwx.firefighting.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.dlwx.firefighting.R;
import com.dlwx.firefighting.bean.AddressBean;

/**
 * 管理收货地址adapter
 */
public class AddressManagerAdapter extends ListBaseAdapter<AddressBean> {
    //默认地址的位置
    private int selectId = 0;
    private OnItemWchClickListener onItemWchClickListener;
    private OnDefaultClickListener onDefaultClickListener;

    public int getSelectId() {
        return selectId;
    }

    public void setSelectId(int selectId) {
        this.selectId = selectId;
    }

    public AddressManagerAdapter(Context context) {
        super(context);
    }

    @Override
    public int getLayoutId() {
        return R.layout.address_manager_item;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, final int position) {
        AddressBean bean = mDataList.get(position);

        final ImageView imageView = holder.getView(R.id.address_manager_img);
        TextView tv_name = holder.getView(R.id.address_manager_name);
        TextView tv_phone = holder.getView(R.id.address_manager_phone);
        TextView tv_address = holder.getView(R.id.address_manager_address);
        final TextView btn_delete = holder.getView(R.id.address_manager_delete);
/*
        if (!TextUtils.isEmpty(bean.consignee_name)) {
            tv_name.setText(bean.consignee_name);
        } else {
            tv_name.setText("");
        }

        if (!TextUtils.isEmpty(bean.consignee_phone)) {
            tv_phone.setText(bean.consignee_phone);
        } else {
            tv_phone.setText("");
        }

        if (!TextUtils.isEmpty(bean.consignee_address)) {
            tv_address.setText(bean.consignee_address);
        } else {
            tv_address.setText("");
        }*/

        if (position == 0) {
            imageView.setImageResource(R.mipmap.select_box_yes);
        } else {
            imageView.setImageResource(R.mipmap.select_box_no);
        }

        if (onDefaultClickListener != null) {
            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onDefaultClickListener.onItemClick(imageView, position);
                }
            });
        }

        if (onItemWchClickListener != null) {
            btn_delete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onItemWchClickListener.onItemClick(btn_delete, position);
                }
            });
        }
    }

    /**
     * 删除地址接口
     */
    public interface OnItemWchClickListener {
        void onItemClick(View view, int position);
    }

    public void setOnItemWchClickListener(OnItemWchClickListener onItemWchClickListener) {
        this.onItemWchClickListener = onItemWchClickListener;
    }

    /**
     * 设置默认地址接口
     */
    public interface OnDefaultClickListener {
        void onItemClick(View view, int position);
    }

    public void setOnDefaultClickListener(OnDefaultClickListener onDefaultClickListener) {
        this.onDefaultClickListener = onDefaultClickListener;
    }
}
